//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"
var myVariable = 42
myVariable = 50


let label = "The width is"
let width = 94
//两种数值转化为字符串
let widthLabel=label + String(width)
let add = label + "\(width)"
let sum1 = "i have \(3) pirces of fruit"
let name = label + "\(width)"
//数组
var shop1=[String]() //空数组
var shop = ["food","fruit","cloth"]

//字典
var dic=[String:Float]()//空字典
var dic1=["food":"rice","fruit":"apple"]

//逻辑判断
let individualScore=[60,80,100]
var teamSc = 0
for score in individualScore {
    if score > 80 {
        teamSc+=9
    }
    else{
        teamSc+=1
    }
}
print(teamSc)

//下面两个一个意思
// 1
var n = 2
while n < 100 {
    n=n*2
}
print(n)

// 2
var m = 2
repeat
{
  m=m*2
}
while m < 100
print(m)


//自定义函数的书写 其中 -> String 指的是返回值类型 greet 方法名
func greet(person:String,food:String)-> String{
    
    return "hello\(person),今天吃了\(m)条\(food)."
}
print(greet(person: "李发林", food: "鱼")

//求平均值
func sumOf(numbers: Int...) -> Int {
    var sum = 0
    var q = 0
    for number in numbers {
        sum += number
        q = sum/numbers.count
    }
    return q
}
sumOf()
sumOf(numbers: 42, 597, 12,90)


func returnFifteen() -> Int {
    var y = 10
    func add() {
        y += 5
    }
    add()
    return y
}
returnFifteen()

//类 的对象和属性
class Shape {  //Shape 类名
    
    var numberOfSides = 0  //属性
    func simpleDescription() -> String //方法
    {
        return "A shape with \(numberOfSides) sides."
    }
    
}

var shape = Shape()
shape.numberOfSides=2
shape .simpleDescription()
print(shape.numberOfSides)


//协议和扩展 exampleProtocol 协议名
protocol exampleProtocol{
    var simpleDescription:String
    {
        get
    }
    mutating func adjust()
}

class SiClass:exampleProtocol{
    var simpleDescription: String = "lfl is cool"
    func adjust() {
        simpleDescription+="shuai"
    }
    
    
}
var a=SiClass()
a.simpleDescription
a.adjust()

var lfl : String

var lfl1 ,wmy:String

let 你好 = "nihao"

var number = "123"
number.insert("5", at: number.startIndex)
number.remove(at:number.startIndex)
let intnumber=Int(number)
if let Number=Int(number) {
    print("\'\(number)\' has an integer value of \(Number)")
} else {
    print("\'\(number)\' could not be converted to an integer")
}

var(x,y)=("12312",2)
print(x,y)

print("hello,"+"world")





















